<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

  
    protected $guarded = ['id'];

 
    protected $hidden = [
         
    ];

    protected $appends = ['xueli_txt','age','photo','is_havebaby_txt','is_smoke_txt','is_ill_txt','is_married_txt','is_wantbaby_txt'];

    public function xueli()
    {
        return $this->belongsTo(Dict::class,'xueli_rank','rank');
    }

    public function getPhotoAttribute()
    {
        return $this->avatar?config('app.url').$this->avatar:$this->wx_avatar;
    }

    public function getIsHavebabyTxtAttribute()
    {
        return $this->is_havebaby==1?'有':'无';
    }

    public function getIsSmokeTxtAttribute()
    {
        return $this->is_smoke==1?'是':'否';
    }

    public function getIsIllTxtAttribute()
    {
        return $this->is_ill==1?'是':'否';
    }

    public function getIsWantbabyTxtAttribute()
    {
        return $this->is_wantbaby==1?'是':'否';
    }

    public function getIsMarriedTxtAttribute()
    {
        return $this->is_married==1?'是':'否';
    }
   

    

  

    public function getXueliTxtAttribute()
    {
        return object_get($this->xueli,'name');
    }

    public function coupon()
    {
        return $this->hasMany(UserCoupon::class);
    }

    public function getAgeAttribute()
    {
        $current_year = date('Y');
        if($this->birthday) {
            $birth_year   = substr($this->birthday,0,4);
            return (int)($current_year-$birth_year);    
        }
        return null;
        
    }

    public function coord()
    {
        return $this->hasOne(UserCoordinate::class);
    }

    
}
